//
//  WHZTabBarController.m
//  WHZGuDong
//
//  Created by whz on 16/11/8.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WHZTabBarController.h"
#import "WHZNavigationController.h"
#import "WHZSportsHomeViewController.h"
#import "WHZDiscoverViewController.h"
#import "WHZSportsViewController.h"
#import "WHZShoppingViewController.h"
#import "WHZMineViewController.h"

@interface WHZTabBarController ()

@end

@implementation WHZTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    // MARK: - 初始化UI
    [self setupUI];
}

#pragma mark - 初始化UI
- (void) setupUI {

    UIViewController *vc1 = [self loadChildViewControllerWithClassName:@"WHZSportsHomeViewController" andTitle:@"运动圈" andImageName:nil];
    UIViewController *vc2 = [self loadChildViewControllerWithClassName:@"WHZDiscoverViewController" andTitle:@"发现" andImageName:nil];
    UIViewController *vc3 = [self loadChildViewControllerWithClassName:@"WHZSportsViewController" andTitle:@"运动" andImageName:nil];
    UIViewController *vc4 = [self loadChildViewControllerWithClassName:@"WHZShoppingViewController" andTitle:@"商城" andImageName:nil];
    UIViewController *vc5 = [self loadChildViewControllerWithClassName:@"WHZMineViewController" andTitle:@"我的" andImageName:nil];
    
    self.viewControllers = @[vc1,vc2,vc3,vc4,vc5];
}

#pragma mark - 创建子控制器
/**
 加载子控制器
 
 @param className 子控制器名字
 @param title     标题
 @param imageName 图片
 
 @return 子控制器
 */
- (UIViewController *) loadChildViewControllerWithClassName:(NSString *)className andTitle:(NSString *)title andImageName:(NSString *)imageName {
    
    Class class = NSClassFromString(className);
    UIViewController *vc = [[class alloc] init];
    
    return [self setupWithViewController:vc andTitle:title andImageName:imageName];;
}

#pragma mark - 返回一个导航控制器
/**
 返回一个导航控制器
 
 @param vc        子控制器
 @param title     控制器标题
 @param imageName 图片
 
 @return 导航控制器
 */
- (UIViewController *) setupWithViewController:(UIViewController *)vc andTitle:(NSString *)title andImageName:(NSString *)imageName {
    
    vc.title = title;
    vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[imageName stringByAppendingString:@"_selected"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    WHZNavigationController *nav = [[WHZNavigationController alloc] initWithRootViewController:vc];
    
    return nav;
}

@end
